fix(web): add Safari fallback for requestIdleCallback#9137
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR centralizes idle-callback handling with requestIdle/cancelIdle wrappers, installs those wrappers into globalThis during module initialization, and imports the polyfills module in the client entry before React hydration. ChangesSafari requestIdleCallback Polyfill Setup
Sequence Diagram(s)sequenceDiagram
participant Client as entry.client
participant Polyfills as polyfills/index
participant IdleTask as idle-task.installIdleCallbackPolyfill
participant Global as globalThis
participant Runtime as runtime (task scheduling)
Client->>Polyfills: import & execute (void polyfills)
Polyfills->>IdleTask: installIdleCallbackPolyfill()
IdleTask->>Global: set requestIdleCallback / cancelIdleCallback (native or fallback)
Client->>IdleTask: runIdleTask(callback) -> requestIdle(callback, {timeout:300})
IdleTask->>Runtime: schedule via globalThis.requestIdleCallback or setTimeout
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/core/lib/idle-task.ts`:
- Around line 11-37: The fallback implementations and availability checks should
use globalThis instead of window to avoid runtime errors when window is
undefined: update requestIdleFallback and cancelIdleFallback to call
globalThis.setTimeout and globalThis.clearTimeout, and change the runtime checks
in requestIdle and cancelIdle to use typeof globalThis !== "undefined" and
typeof globalThis.requestIdleCallback / globalThis.cancelIdleCallback ===
"function" so you only call globalThis.requestIdleCallback(globalCallback,
options) when available and otherwise return requestIdleFallback(callback) /
cancelIdleFallback(id).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2707e4a8-912b-4ba0-864a-2c084b23bf1d
📒 Files selected for processing (3)
apps/web/app/entry.client.tsxapps/web/core/lib/idle-task.tsapps/web/core/lib/polyfills/index.ts
Switch idle-task fallback paths from window.* to globalThis.* so the fallback no longer crashes in environments where window is undefined. Also thread IdleRequestOptions through requestIdleFallback so the caller's timeout hint is honored when falling back. Addresses CodeRabbit review feedback on makeplane#9137.
|
Actionable comments posted: 0 |
Description
Fixes a Safari/iOS crash caused by unguarded usage of
window.requestIdleCallbackin the project layout/gantt view.Safari does not currently support
requestIdleCallbackby default, which caused the following runtime error:TypeError: window.requestIdleCallback is not a functionThis PR adds a shared compatibility fallback for:
requestIdleCallbackcancelIdleCallbackThe polyfill is installed during client startup before React hydration, while preserving native behavior in Chrome and Firefox.
Type of Change
Screenshots and Media (if applicable)
N/A
Test Scenarios
requestIdleCallbackis unavailableReferences
Closes #9134
Summary by CodeRabbit